<template>
  <div class="mod-menu">
    <div class="mb10">
      <el-button @click="getBack">返回管理商品</el-button>
    </div>
    <el-form :inline="true" :model="dataForm">
      <el-form-item label="商品名称">
        <el-input v-model="dataForm.userName" placeholder="商品名称" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">查询</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="dataList" row-key="Id" border style="width: 100%; ">
      <el-table-column prop="title" align="center" label="商品名称">
      </el-table-column>
      <el-table-column prop="min_sale_price" align="center" label="销售价格">
      </el-table-column>
      <!-- <el-table-column prop="" align="center" label="成本价格">
      </el-table-column> -->
      <el-table-column prop="added" align="center" :formatter="added" label="商品状态">
      </el-table-column>
      <el-table-column prop="real_sale_num" align="center" label="实际销量">
      </el-table-column>
      <el-table-column prop="is_join" align="center" label="是否已参加拼团">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.is_join">是</el-tag>
          <el-tag v-else type="success">否</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="residual_inventory" align="center" label="实际库存">
      </el-table-column>
      <el-table-column fixed="right" header-align="center" align="center" label="操作">
        <template slot-scope="scope" v-if="scope.row.is_join==false">
          <el-button  type="text" size="small" @click="addOrUpdateHandle(scope.row.id)">添加</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pamars.page"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pamars.limit"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper"
    ></el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <gb-pd-add v-if="addOrUpdateVisible" ref="gbPdAdd" @updataList='getBack'></gb-pd-add>
  </div>
</template>

<script>
  import gbPdAdd from './gb-pd-add'
  import seviceApi from '@/api/serviceApi.js'
  export default {
    data () {
      return {
        dataForm: {},
        pamars: {
          page: 1,
          limit: 10,
          title: '',
          group_buy_id: ''
        },
        totalPage: 0,
        dataList: [],
        dataListLoading: false,
        addOrUpdateVisible: false
      }
    },
    components: {
      gbPdAdd
    },
    watch: {
      '$route' () {
        this.getList()
  }},
    mounted () {
      this.pamars.group_buy_id = this.$route.query.id
      this.getList()
    },
    methods: {

      added (row, column) {
        let status = row.added
        if (status === true) {
          return '上架'
        } else {
          return '下架'
        }
      },
      // 获取列表
      getList () {
        seviceApi.getforactivitylist(this.pamars).then(res => {
          if (res && res.data.code == 200) {
            this.dataList = res.data.page.list
            this.totalPage = res.data.page.totalCount
          }
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pamars.limit = val
        this.getList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pamars.page = val
        this.getList()
      },
      // 查询
      getDataList () {
        this.pamars.page = 1
        this.getList()
      },
      // 新增 / 修改
      addOrUpdateHandle (id) {
        this.addOrUpdateVisible = true
        this.$nextTick(() => {
          this.$refs.gbPdAdd.init('', this.pamars.group_buy_id, id)
        })
      },
    // 返回管理商品
      getBack () {
        this.$router.go(-1)
      }
    }
  }
</script>
<style>
  .mb10{
    margin-bottom: 10px;
  }
</style>
